package com.code.day15DuoXianC.Runnable05;

public class MyRunnable implements Runnable {
    static int tickets = 100;
    Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            method();
        }
    }

    public static synchronized void method() {
        if (tickets > 0) {
            System.out.println(Thread.currentThread().getName() + "正在卖第" + tickets + "张票");
            tickets--;
        }
    }
}
